import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],

  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },

  define: {
    'process.env': {
      'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
      'VITE_MODE': JSON.stringify(process.env.VITE_MODE),
      'VITE_API_URL': JSON.stringify(process.env.VITE_API_URL),
    },
    globalVar: {name: '我的全局变量'}
  },
  base: process.env.VITE_MODE === 'development' ? '/qqq' : '/',
  server: {
   host: '0.0.0.0',
   open: true,
   port: 8888,
   proxy: {
     '/api': {
       target: 'http://localhost:3000',
       changeOrigin: true,
       rewrite: (path) => path.replace(/^\/api/, '')
     }
   } 
  }
})
